package com.example.testdemo.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * author: MaHX
 * date: 2020/9/11/0:39
 * description:
 **/
@RestController
public class TestController {
    @Autowired
    MongoTemplate mongoTemplate;

    @PostMapping("test")
    public List<Object> get(@RequestParam String collection, @RequestParam Map param) {
        Query query = new Query();
        Criteria criteria = Criteria.where("code").is("base");
        query.addCriteria(criteria);
        List<Object> result = mongoTemplate.find(query, Object.class,collection);
        return result;
    }
}
